package dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import dao.LoginDao;
import vo.Person;
@Repository("ld")
public class LoginDaoImpl implements LoginDao{
	@PersistenceContext(name="un")
	private EntityManager em;
	@Override
	public Person find(String username, String passwd) {
		Person p=null;
		//String jpql="select s from Student s where s.xh=:xh and s.psd=:psd";
		// where p.username=:username and p.passwd=:passwd
		String sql="select p from Person p where p.username=:username and p.passwd=:passwd";
		List<Person> ls=em.createQuery(sql)
				.setParameter("username", username)
				.setParameter("passwd", passwd)
				.getResultList();
		
		if(ls.isEmpty()) return null;
		else return ls.get(0);
	}

	@Override
	public int add(Person p) {
		int rs=0;
		em.persist(p);
		return p.getId();
	}

}
